FROM node:20-alpine AS build-stage

WORKDIR /app
RUN corepack enable
RUN corepack prepare pnpm@latest --activate

RUN npm config set registry https://registry.npmmirror.com

COPY .npmrc package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile

COPY . .
RUN pnpm build

FROM registry.cn-shanghai.aliyuncs.com/eian-images/nginx-brotli:stable-alpine AS production-stage

COPY --from=build-stage /app/dist /usr/share/nginx/html

COPY ./deploy/nginx.conf /etc/nginx/nginx.conf.template
COPY ./deploy/docker-entrypoint.sh /

# 设置环境变量，默认后端API地址
ENV BACKEND_API_URL=http://127.0.0.1:8080

# 设置执行权限
RUN chmod +x /docker-entrypoint.sh

EXPOSE 80

# 启动脚本
ENTRYPOINT ["/docker-entrypoint.sh"]